home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_200 / 292_02 / ast05.asm < prev    next >
Assembly Source File  |  1990-07-16  |  27KB  |  1,246 lines

  1.     .title    assist05E2 february 18, 1985
  2. ;*
  3. ;*        monitor for the MC146805E2 Evaluation Board
  4. ;*
  5. ;*     (c) copyright 1985 motorola, inc.
  6. ;*
  7. ;*
  8. ;*    the monitor has the following commands:
  9. ;*
  10. ;*    r        print registers
  11. ;*
  12. ;*    d        download from standard host
  13. ;*
  14. ;*    h        host communication
  15. ;*
  16. ;*    a        display/change a register
  17. ;*
  18. ;*    x        display/change x register
  19. ;*
  20. ;*    c        display/change condition codes
  21. ;*
  22. ;*    e        display/change timer data register
  23. ;*
  24. ;*    f        display/change timer control register
  25. ;*
  26. ;*    p        display/change program counter
  27. ;*
  28. ;*    i        display/change irq vector
  29. ;*
  30. ;*    j        display/change timer vector
  31. ;*
  32. ;*    k        display/change timer vector (wait mode)
  33. ;*
  34. ;*    b        display breakpoints
  35. ;*
  36. ;*    b n xxxx    set breakpoint n
  37. ;*
  38. ;*    b n 0        clear breakpoint 
  39. ;*
  40. ;*    t        trace one instruction
  41. ;* 
  42. ;*    t xxxx     trace xxxx instructions
  43. ;*
  44. ;*    m xxxx     memory examine/change
  45. ;*
  46. ;*        type    <cr>    to examine next
  47. ;*            ^    to eamine previous
  48. ;*            =    to examine same
  49. ;*            hh    to change hex data
  50. ;*            .    to terminate command
  51. ;*
  52. ;*    g        continue execution from current pc
  53. ;*
  54. ;*    g xxxx        go execute pgm at specified address
  55. ;*
  56. ;*
  57. ;*
  58. ;*
  59. ;*
  60. ;*
  61. ;*
  62. ;*
  63. monstr    =    0x1800    ; start of monitor
  64. workpg    =    0x0010    ; start of monitor variables
  65. numbkp    =    3    ; number of breakpoints
  66. duart    =    0x17f0    ; duart address
  67. prompt    =    '>    ; prompt character
  68. timer    =    8    ; timer data register
  69. timec    =    9    ; timer control register
  70. ;*
  71. ;*        equates
  72. ;*
  73. ;*
  74. eot    =    0x04    ; end of text
  75. cr    =    0x0d    ; carriage return
  76. lf    =    0x0a    ; line feed
  77. sp    =    0x20    ; space
  78. bell    =    0x07    ; control-g (bell)
  79. swiop    =    0x83    ; software interrupt op code
  80. jmpop    =    0xcc    ; extended jump op code
  81. ctla    =    0x01    ; host communications default terminator
  82. ;*
  83. ;*        work ram 
  84. ;*
  85. ;*
  86.     .area    ASST05    (ABS,OVR)
  87.  
  88.     .setdp
  89.  
  90.     .org    workpg
  91.  
  92. bkptbl:    .blkb  3*numbkp    ; breakpoint table
  93. asave:    .blkb    1    ; temp save for a 
  94. swiflg:    .blkb    1    ; swi function flag
  95. work1:    .blkb    1    ; chrin/load/store/putbyt
  96. work2:    .blkb    1    ; load/store/putbyte 
  97. addrh:    .blkb    1    ; high address byte
  98. addrl:    .blkb    1    ; low address byte
  99. work3:    .blkb    1    ; load/store/punch
  100. work4:    .blkb    1    ; store/punchpunch
  101. work5:    .blkb    1    ; trace/punch
  102. work6:    .blkb    1    ; trace
  103. work7:    .blkb    1    ; trace
  104. work8:    .blkb    1    ; timer restoration
  105. work9:    .blkb    1    ; timer restoration
  106. workd:    .blkb    1    ; timer restoration
  107. worke:    .blkb    1    ; timer restoration
  108. pncnt:    .blkb    1    ; punch breakpoint
  109. chksum:    .blkb    1    ; punch
  110. cmd:    .blkb    3
  111. total:    .blkb    1
  112. savea:    .blkb    1
  113. sava:    .blkb    1
  114. savex:    .blkb    1
  115. vecram:    .blkb    12    ; vectors
  116. ;*
  117. ;*
  118. ;*
  119. ;*
  120. ;*
  121.     .org    monstr    ; start of monitor
  122. ;*
  123. ;*        monitor base string/table page
  124. ;*        (must be at the begining of a page)
  125. ;*
  126. ;*
  127. ;*
  128. mbase    =    .    ; start of work page in rom
  129. ;*            ; msgup must be the first in the page
  130. msgup:    .ascii    /assist05E2 3.0/    ; fire-up message
  131. msgnul:    .byte    eot            ; end of string
  132. msgerr:    .ascii    /- error -/
  133.     .byte    bell
  134.     .byte    eot
  135. msgpc:    .ascii    /  Pc  A  X  Cc S/
  136.     .byte    eot
  137. vectab:    .byte    jmpop
  138.     .word    tirq
  139.     .byte    jmpop
  140.     .word    tirq 
  141.     .byte    jmpop
  142.     .word    irq
  143.     .byte    jmpop
  144.     .word    swi
  145. ;*
  146. ;*
  147. ;*    g - start execuction
  148. ;*        also used for p - display/set pc
  149. ;*
  150. ;*
  151. cmdg:    lda    *work4
  152.     bit    #0x80
  153.     bne    nodipc        ; don't display pc if a g command
  154.     jsr    putsp        ; send a space
  155.     jsr    locstk        ; obtain current sp-3
  156.     lda    7,x        ; current pc high
  157.     jsr    putbyt        ; print pc high in hex
  158.     lda    8,x        ; current pc low
  159.     jsr    putbyt        ; print pc low in hex
  160. nodipc:    jsr    getadr        ; obtain input address
  161.     bcc    next        ; do continue if done
  162. gaddr:    jsr    locstk        ; obtain current sp-3t-3
  163.     lda    *addrh        ; load pc high
  164.     sta    7,x        ; into stack
  165.     lda    *addrl        ; load pc low
  166.     sta    8,x        ; into stack also
  167. next:    lda    *work4
  168.     bit    #0x80
  169.     bne    cont        ; if g command then continue
  170.     jmp    cmdnnl        ; else just p command - don't continue
  171. cont:    jsr    scnbkp        ; init breakpoint scan parameters
  172. goinsb:    lda    *bkptbl,x     ; load high byte
  173.  
  174.     cmp    #0x00        ; check to see if empty
  175.     bne    gstore
  176.     lda    *bkptbl+1,x    ; get next byte
  177.     cmp    #0x00        ; really empty?
  178.     beq    gonob
  179.  
  180. gstore:    lda    *bkptbl,x    ; go get byte again
  181.     sta    *addrh        ; store high address
  182. sta:    lda    *bkptbl+1,x     ; load low address
  183.     sta    *addrl        ; load low
  184.     jsr    load        ; load opccode 
  185.     sta    *bkptbl+2,x    ; store into table
  186.     lda    #swiop    ;     replace with opcode
  187.     jsr    store        ; store in place
  188. gonob:    incx            ; to
  189.     incx            ; next
  190.     incx            ; breakpoint
  191.     lda    *pncnt        ; count low
  192.     deca
  193.     sta    *pncnt
  194.     bne    goinsb        ; loop if more
  195.     lda    *swiflg        ; flag breakpoints are in
  196.     coma
  197.     sta    *swiflg
  198.     lda    *work9        ; reset control register 
  199.     sta    *timec
  200.     lda    *work8
  201.     sta    *timer        ; then user enviornment
  202.     lda    *workd        ; then the user's vectors
  203.     sta    *vecram+4
  204.     lda    *worke
  205.     sta    *vecram+5
  206.     rti            ; restart program
  207. cmdmin:    jmp    cmderr
  208. ;*
  209. ;*
  210. ;*    m - examine/change memory
  211. ;*    mchnge - register change entry point
  212. ;*
  213. ;*
  214. ;*
  215. cmdm:    jsr    getadr        ; obtain address value
  216.     bcc    cmdmin        ; invalid if no address
  217. cmdmlp:    jsr    prtadr        ; print out address and space
  218. mchnge:    bsr    load        ; load acc w/byte
  219.     jsr    crbyts        ; print with a space
  220.     jsr    getnyb        ; see if change wanted
  221.     bcc    cmdmdl        ; branch no
  222.     jsr    getby2        ; obtain full byte
  223.     bne    cmdmin        ; terminate if invalid hex
  224.     bcc    cmdmdl        ; branch if other delimiter
  225.     bsr    store        ; store new value
  226.     bcs    cmdmin        ; branch of store fails
  227.     jsr    chrin        ; obtain delimiter
  228. ;*
  229. ;*    check out delimiters 
  230. cmdmdl:    cmp    #0x0d        ; ? to next byte
  231.     beq    cmdmlf        ; branch if so
  232.     cmp    #'^        ; ? to previous byte
  233.     beq    cmdmbk        ; branch if so
  234.     cmp    #'=        ; ? reexamine same byte
  235.     beq    cmcmpr        ; branch yes
  236.     cmp    #'.        ; ? carriage return
  237.     beq    cmdmen1        ; branch yes
  238.     jsr    pcrlf        ; all else: give new line
  239. cmdmen:    jmp    cmdnnl        ; enter command handler
  240. cmdmbk:    lda    *addrl        ; ? low byte zero?
  241.     bne    cmdmb2        ; no, just adjust it
  242.     lda    *addrh
  243.     deca
  244.     sta    *addrh        ; down high for carry
  245. cmdmb2:    lda    *addrl
  246.     deca
  247.     sta    *addrl        ; down low byte
  248.     bsr    pcrlf        ; to next line
  249.     bra    cmdmlp        ; to next byte
  250. cmcmpr:    bsr    pcrlf
  251.     bra    cmdmlp
  252. cmdmlf:    lda    #cr        ; send just a carriage return
  253.     jsr    chrou2        ; output it
  254.     bsr    ptrup1        ; up pointer by one
  255.     bra    cmdmlp        ; to next byte
  256.  
  257. cmdmen1:
  258.     jsr    pcrlf
  259.     bra    cmdmen        ; add crlf to the <.>
  260. ;*
  261. ;*
  262. ;*    load - load into a from address pointer addrh/addrl
  263. ;*
  264. ;*        input:    addrh/addrl = address
  265. ;*
  266. ;*        output: a=byte from pointed location
  267. ;*            x is transparent
  268. ;*            work1, work2, work3 used
  269. ;*
  270. ;*
  271. load:    stx    *work1        ; save x
  272.     ldx    #0xc6        ; c6=lda 2 byte extended
  273. ldstcm:    stx    *work2        ; put opcode in place
  274.     ldx    #0x81        ; 81=rts
  275.     stx    *work3        ; now the return
  276.     jsr    *work2        ; execute built in routine
  277.     ldx    *work1        ; restore x
  278.     rts            ; and exit
  279. ;*
  280. ;*
  281. ;*    store - store a at address in pointer addrh/addrl
  282. ;*
  283. ;*        input:    a=byte to store
  284. ;*            addrh/addrl= address
  285. ;*        output:    c=0 store went ok
  286. ;*            c=1 store did not take (not ram)
  287. ;*            registers transparent (a not transparent on
  288. ;*            invalid store) 
  289. ;*
  290. ;*
  291. store:    stx    *work1        ; save x
  292.     ldx    #0xc7        ; c7=sta 2 byte extended
  293.     bsr    ldstcm        ; call store routine
  294.     sta    *work4        ; save value stored
  295.     bsr    load        ; attempt load
  296.     cmp    *work4        ; valid store?
  297.     beq    strts        ; branch if valid
  298.     sec            ; show invalid store
  299. strts:    rts            ; return
  300. ;*
  301. ;*
  302. ;*    ptrup1 - increment memory pointer
  303. ;*
  304. ;*
  305. ptrup1:    lda    *addrl
  306.     inca
  307.     sta    *addrl        ; increment low byte
  308.     bne    prtrts        ; non zero means no carry
  309.     lda    *addrh
  310.     inca
  311.     sta    *addrh        ; increment high byte
  312. prtrts:    rts            ; return to caller
  313. ;*
  314. ;*
  315. ;*    putbyt - print a in hex
  316. ;*
  317. putbyt:    sta    *work1        ; save a
  318.     lsra            ; shift to 
  319.     lsra            ; left hex
  320.     lsra            ; digit
  321.     lsra            ; shift high nybble down
  322.     bsr    putnyb        ; print it
  323.     lda    *work1
  324. ;*
  325. ;*    fall into putnyb
  326. ;*
  327. ;*
  328. ;*    putnyb - print lower nybble of a in hex
  329. ;*        a,x transparent
  330. ;*
  331. ;*
  332. putnyb:    and    #0xf        ; mask off high nybble
  333.     add    #'0        ; add ascii zero
  334.     cmp    #'9        ; check for a-f
  335.     bhi    putny2
  336.     jmp    chrout        ; ok, send out
  337. putny2:    add    #'a-'9-1     ; adjustment for hex a-f
  338.     jmp    chrout        ; now send out
  339. ;*
  340. ;*
  341. ;*    pdata    - print monitor string after cr/lf
  342. ;*    pdata1    - print monitor string
  343. ;*    pcrlf    - print cr/lf
  344. ;*
  345. ;*    input: x=offset to string in base page
  346. ;*
  347. ;*
  348. pcrlf:    ldx    #msgnul-mbase    ; load null string address
  349. pdata:    lda    #cr        ; prepare carriage return
  350. pdloop:    jsr    chrout        ; send next character
  351. pdata1:    lda    mbase,x        ; load next character
  352.     incx